找传奇、传世资源到传世资源站!

mosca mqtt broker示例源码(nodejs 服务端源码)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

from clipboardvar mosca = require('mosca');const StringDecoder = require('string_decoder').StringDecoder;let decoder = new StringDecoder('utf8');var ascoltatore = { type: 'redis', redis: require('redis'), db: 12, port: 6379, return_buffers: true, // to handle binary payloads host: "localhost"};var settings = { port: 11883, backend: ascoltatore};var server = new mosca.Server(settings);server.on('clientConnected', function(client) { console.log('client connected', client.id);});// fired when a message is receivedserver.on('published', function(packet, client) { console.log('Published', packet.payload); console.log('topic',decoder.write(packet.topic)); console.log('payload',decoder.write(packet.payload));});server.on('ready', setup);// fired when the mqtt server is readyfunction setup() { console.log('Mosca server is up and running'); server.authenticate = authenticate;}var authenticate = function(client, username, password, callback) { console.log('authenticate---->' client.id ',' username ',' password); callback(null, true);//验证通过 // callback(null, false);//验证未通过}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复